﻿using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

namespace YanhuaMMO {
    public class AppConst {
        public static bool DebugMode = false;                       //调试模式-用于内部测试
        public static bool BundleMode = false;
        public static bool LanguageMode = true;                    //开启多语言
        public static LanguageType DefalutLanguageType = LanguageType.Chinese;                    //开启多语言

        /// <summary>
        /// 如果开启更新模式，前提必须启动框架自带服务器端。
        /// 否则就需要自己将StreamingAssets里面的所有内容
        /// 复制到自己的Webserver上面，并修改下面的WebUrl。

        /// </summary>
        public static bool UpdateMode = false;                       //更新模式-默认关闭
        public static bool LuaByteMode = true;                       //Lua字节码模式-默认关闭 
        public static bool LuaBundleMode = false;                    //Lua代码AssetBundle模式

        public const int TimerInterval = 1;
        public const int GameFrameRate = 30;                        //游戏帧频
        public const float HeightWidthRatio = 1.75f;                //最低宽高比，低于此值，两侧显示黑框； 设计分辨率1920/1080=1.7777...可以比1.77低一些。等于0时，关闭该功能
        public static bool UseBlackCover = false;                    //是否使用了宽屏黑边
        public const int DesignResolutionX = 1080;
        public const int DesignResolutionY = 1920;              //设计分辨率

        public const string AppName = "YanhuaMMO";               //应用程序名称
        public const string LuaTempDir = "Lua/";                    //临时目录
        public const string Lua64TempDir = "Lua64/";                    //临时目录
        public const string AppPrefix = AppName + "_";              //应用程序前缀
        public const string ExtName = ".unity3d";                   //素材扩展名
        public const string AssetDir = "StreamingAssets";           //素材目录
		public static int drawingState = 1;                     //和谐立绘状态 1 和谐状态   0 普通状态
        public static int forceChannel = 0;                         //指定渠道，0则不修改
        public const int auditChannel = 150;                        //指定审核渠道
        public const int auditIOSChannel = 44;                        //指定审核渠道
        public static string remoteConfigStr = "";//远程配置文件
		public const bool isBussiness = false;
        public const string BranchPath = "/fuiBranch";              //fui分支资源bundle文件临时存放地址
        public const string BranchUrl = "https://feishigame-pro.oss-cn-shanghai.aliyuncs.com/update/fuibranch/";

#if UNITY_IOS
        public const string _WebUrl = "https://fsgame.xiaoniuhy.com/update/ios/{0}/";      //测试更新地址
#elif UNITY_ANDROID || UNITY_EDITOR
        public const string _WebUrl = "https://fsgame.xiaoniuhy.com/update/android/{0}/";      //测试更新地址
        //public const string WebUrl = "https://ytm-real.oss-cn-shanghai.aliyuncs.com/android";      //更新地址
        //public const string WebUrl = "https://47.103.144.72/asset/androidtest/";      //测试更新地址
#endif

        public static string UserId = string.Empty;                 //用户ID
        public static string UserToken = string.Empty;                 //用户ID

        public static int SocketPort = 0;                           //Socket服务器端口
        public static string SocketAddress = string.Empty;          //Socket服务器地址
        public static int ServerId = 0;

        public static bool connect = false;//socket是否已连接
        public static bool sceneconnect = false;//战场socket是否已连接
        public static bool disconnect  = false;//游戏中断线
        public static bool joystickMode = false;//摇杆模式
        // (1大版本号，基本不动）.
        //（2渠道号非平台渠道，）.
        //（3大更新，换包）.
        //（4小补丁，热更，固定最4位）.
        // 5、（SVN修改号，待定）
        public static string appVersion = originVersion;
        public const string originVersion = "1.4.3.0001";//与appVersion保持一致，但是不能赋值。
        public static bool delayLoadModel = false;//延迟更新地图资源，加快进入游戏

        public static string debugMsg = "";
        public static string FrameworkRoot {
            get {
                return Application.dataPath + "/project";
            }
        }
        public static string ReplaceResourcesRoot
        {
            get
            {
                return "Assets/ReplaceResources/";
            }
        }
        public static int ChannelId = 1;
        public static int SubChannel = -1;

        public static string WebUrl
        {
            get 
            {
                ChannelId = LoginSDK.GetInstance().GetCurChannel();
                int.TryParse(LoginSDK.GetInstance().GetSubChannel(), out SubChannel);

                //官方渠道下，通过子渠道号，预留了几个渠道

                if (forceChannel > 0)
                {
                    ChannelId = forceChannel;
                }
                else
                {
                    if (ChannelId == 39)
                    {
                        if (SubChannel == 492 || SubChannel == 493 || (SubChannel >= 511 && SubChannel <= 530) || (SubChannel >= 547 && SubChannel <= 747))
                        {
                            ChannelId = SubChannel;
                        }
                    }
                }
                string path = string.Format(_WebUrl, ChannelId);
                if(Application.platform == RuntimePlatform.IPhonePlayer)
                {
                    //苹果就一个渠道，目前是44，苹果的U8没有单独返回channelId的接口
                    if (forceChannel > 0)
                    {
                        path = string.Format(_WebUrl, forceChannel);
                    }
                    else
                    {
                        path = string.Format(_WebUrl, 100);
                    }
                }
                return path;
            }
        }
    }
}